/*
 *  OHAI.cpp
 *  TubeTruck
 *
 *  Created by Aeturnum on 6/3/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include "OHAI.h"

using namespace TTP;
using namespace std;

OHAI::OHAI() : Packet(Packet_OHAI)
{}
OHAI::OHAI(id_hash idHash) : Packet(idHash, Packet_OHAI)
{}
OHAI::~OHAI() {}

void OHAI::setSourceIdHash(id_hash idHash) {
   mIdHash = idHash;
}

id_hash OHAI::getSourceIdHash() const {
   return mIdHash;
}

void OHAI::fromVec(std::vector<byte>::const_iterator &vit, std::vector<byte>::const_iterator &end) {
   Packet::fromVec(vit, end);
   hashFromVec(vit);
   if(!verifyHash()) {
      throw msg_exception("OHAI packet failed consistancy check.");
   }
}

void OHAI::toVec(std::vector<byte> &vec) const {
   Packet::toVec(vec);
   hashToVec(vec);
}

vector<byte> OHAI::getHashablePacket() const {
   vector<byte> vec;
   vector<byte> fakeHash(getBlankHash());
   
   Packet::toVec(vec);
   vec.insert(vec.end(), fakeHash.begin(), fakeHash.end());
   return vec;
}